package xcmg.device.service.vo.warehouse;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;

@Data
@NoArgsConstructor
public class WarehouseInventoryHistoryReportResponse {

    public static final String NO_WAREHOUSETYPE_NAME = "未分类";

    private List<String> months;

    private List<ReportData> data;

    public WarehouseInventoryHistoryReportResponse(List<String> months,List<ReportData> data){
        this.setMonths(months);
        this.setData(data);
    }

    @Data
    public class ReportData{
        private String warehouseTypeName;

        private BigDecimal[] data;
    }

    public void sortData(){
        if(CollectionUtils.isEmpty(data)){
            return;
        }
        data.sort(new Comparator<ReportData>() {
            @Override
            public int compare(ReportData o1, ReportData o2) {
                String warehouseTypeName1 = o1.getWarehouseTypeName();
                String warehouseTypeName2 = o2.getWarehouseTypeName();
                if(StringUtils.isEmpty(warehouseTypeName1) || StringUtils.isEmpty(warehouseTypeName2)){
                    return 1;
                }
                if(warehouseTypeName1.equals(NO_WAREHOUSETYPE_NAME)){
                    return 1;
                }
                if(warehouseTypeName2.equals(NO_WAREHOUSETYPE_NAME)){
                    return -1;
                }
                return warehouseTypeName1.compareTo(warehouseTypeName2);
            }
        });
    }
}
